package com.sun.queue;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.LinkedBlockingDeque;

/**
 * 常用的队列ArrayBlockingQueue
 *
 * LinkedBlockingDeque
 */
public class TestBlockQueue {

    public static void main(String[] args) {
        ArrayBlockingQueue<Object> blockingQueue = new ArrayBlockingQueue<>(3);
        blockingQueue.add(66);
        blockingQueue.add(44);
        blockingQueue.add(88);
        //队列是先进先出
        Object remove = blockingQueue.remove();
        System.out.println(remove);
        Object element = blockingQueue.element();
        System.out.println("存在元素:" + element);
        blockingQueue.stream().forEach(System.out::println);

        LinkedBlockingDeque<Object> linkedBlockingDeque = new LinkedBlockingDeque<>(3);
        linkedBlockingDeque.add(1);
        linkedBlockingDeque.add(2);
        linkedBlockingDeque.add(3);

        linkedBlockingDeque.stream().forEach(System.out::println);
    }
}
